var e = require, t = module, n = exports;

Object.defineProperty(n, "__esModule", {
    value: !0
});

var o = e("GameConfig"), i = e("LoadManager"), a = e("UIManager"), r = function() {
    function e() {
        this.enabled = !1, this.recorder = null, this.recorderBtn = null, this.videoId = null, 
        this.videoPath = "", this.callback = null, this.texture = null, this.spriteFrame = null, 
        this.isRecorder = !1;
    }
    return e.getInstance = function() {
        return this._manager || (this._manager = new e()), this._manager;
    }, e.prototype.init = function() {
        var r = this;
        if (GA.isPlatform([ GA.Platform.WeChat, GA.Platform.ByteDance, GA.Platform.Kwaigame ]) && (this.enabled = !o.GC.isVaild("recorder")), 
        this.enabled) if (GA.isWeChat()) this.recorder = GA.PA.getGameRecorder(); else if (GA.isByteDance()) {
            if (GA.PA.getGameRecorderManager && (this.recorder = GA.PA.getGameRecorderManager(), 
            this.recorder)) try {
                this.recorder.onStart(function() {
                    console.log("录屏开始");
                }), this.recorder.onPause(function() {
                    console.log("录屏暂停");
                }), this.recorder.onResume(function() {
                    console.log("录屏继续");
                }), this.recorder.onStop(function(e) {
                    console.log("录屏停止"), r.videoPath = e.videoPath, o.GC.isDebug && a.default.getInstance().showToast({
                        str: e.videoPath
                    }), r.callback && r.callback(e);
                }), this.recorder.onError(function() {
                    console.log("录屏错误");
                });
            } catch (e) {}
        } else if (GA.isPlatform(GA.Platform.Kwaigame)) try {
            this.recorder = ks.getGameRecorder(), console.log("录屏初始化"), this.recorder && (this.recorder.on("start", function() {
                console.log("录屏开始");
            }), this.recorder.on("stop", function(e) {
                console.log("录屏停止"), r.videoId = e.videoID, r.callback(e);
            }), this.recorder.on("pause", function() {
                console.log("录屏暂停");
            }), this.recorder.on("resume", function() {
                console.log("录屏继续");
            }), this.recorder.on("abort", function() {
                console.log("录屏取消");
            }), this.recorder.on("error", function() {
                console.log("录屏错误");
            }));
        } catch (e) {} else console.error("createMediaRecorder is null");
    }, e.prototype.start = function(e) {
        void 0 === e && (e = 10), GA.isWeChat() ? this.recorder && this.recorder.isFrameSupported() && (this.recorder.isSoundSupported() ? this.recorder.start({
            hookBgm: !0
        }) : this.recorder.start()) : GA.isByteDance() ? this.recorder && this.recorder.start({
            duration: e
        }) : GA.isPlatform(GA.Platform.Kwaigame) && this.recorder && this.recorder.start();
    }, e.prototype.stop = function() {
        GA.isWeChat() ? this.recorder && this.recorder.isFrameSupported() && this.recorder.stop() : GA.isByteDance() ? this.recorder && this.recorder.stop() : GA.isPlatform(GA.Platform.Kwaigame) && this.recorder && this.recorder.stop();
    }, e.prototype.pause = function() {
        GA.isWeChat() ? this.recorder && this.recorder.isFrameSupported() && this.recorder.pause() : GA.isByteDance() ? this.recorder && this.recorder.pause() : GA.isPlatform(GA.Platform.Kwaigame) && this.recorder && this.recorder.pause();
    }, e.prototype.resume = function() {
        GA.isWeChat() ? this.recorder && this.recorder.isFrameSupported() && this.recorder.resume() : GA.isByteDance() ? this.recorder && this.recorder.resume() : GA.isPlatform(GA.Platform.Kwaigame) && this.recorder && this.recorder.resume();
    }, e.prototype.abort = function() {
        GA.isWeChat() && this.recorder && this.recorder.isFrameSupported() && this.recorder.abort();
    }, e.prototype.publishVideo = function(e) {
        this.recorder && this.recorder.publishVideo({
            mouldId: e.mouldId,
            video: e.video,
            callback: e.callback
        });
    }, e.prototype.createGameRecorderShareButton = function(t, s) {
        var c = this;
        this.enabled && GA.isWeChat() && i.default.getInstance().loadRes({
            url: "other/recorder",
            type: cc.SpriteFrame
        }).then(function(e) {
            e && console.log(e.getTexture());
            var r = GA.PA.getSystemInfoSync().screenWidth / cc.view.getVisibleSize().width;
            GA.PA.createGameRecorderShareButton && (c.recorderBtn = GA.PA.createGameRecorderShareButton({
                style: {
                    left: (GA.PA.getSystemInfoSync().screenWidth + (2 * s.x - t.width) * r) / 2,
                    top: (GA.PA.getSystemInfoSync().screenHeight - (2 * s.y + t.height) * r) / 2,
                    height: t.height * r,
                    color: "",
                    fontSize: 16,
                    backgroundColor: "#646464",
                    paddingLeft: 24,
                    paddingRight: 24
                },
                image: e ? e.getTexture().url : "",
                icon: "",
                text: "",
                share: {
                    query: o.GC.OfficialOpenid == GA.Info.openId ? "krq_wjycj=9999" : "krq_wjycj=10002",
                    bgm: "",
                    timeRange: [ 0, 6e4 ]
                }
            }));
        });
    }, e.prototype.showGameRecorderShareButton = function() {
        GA.isWeChat() && this.recorderBtn && this.recorderBtn.show();
    }, e.prototype.hideGameRecorderShareButton = function() {
        GA.isWeChat() && this.recorderBtn && this.recorderBtn.hide();
    }, e.prototype.screenShot = function(e) {
        this.texture || (this.texture = new cc.RenderTexture()), this.spriteFrame || (this.spriteFrame = new cc.SpriteFrame(), 
        this.spriteFrame.setFlipY(!0)), this.texture.initWithSize(cc.winSize.width, cc.winSize.height), 
        e.targetTexture = this.texture, e.render(), this.spriteFrame.setTexture(this.texture), 
        e.targetTexture = null;
    }, e._manager = null, e;
}();

n.default = r;